// pages/order/createRute/carWeight/carWeight.js

const app = getApp()

let api = require('../../../../utils/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showcarWeightId:0,
    carDemand: [],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    that.getSetting();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // },
  choose:function(e){

    var that = this;
    var data = that.data;
    var key = e.currentTarget.dataset.key;
    var type = e.currentTarget.dataset.type;
   // console.log
    that.setData({
      [type]: key,
    })
  },

  getSetting: function () {
    var that = this;
    var token = wx.getStorageSync('TOKEN')

    api._get('/setting/get/info/6', '', token).then(res => {
     // console.log(res);
      if (res.code == 200) {
        that.setData({
          carDemand: res.result
        })
      }
    }).catch(e => {
     // console.log(e)
    })
  },
  /**
   * 提交
   */
  returnCarWeight: function (e) {
    var that = this;
    var data = that.data;
    var vehicleLoad = data.carDemand[data.showcarWeightId].content;

   // console.log(data);
    var pages = getCurrentPages();

    var prevPage = pages[pages.length - 2]; //当前页面的上一个页面

    prevPage.setData({
      vehicleLoad: vehicleLoad,
    })
    wx.navigateBack({

      delta: 1,

    })

    // wx.navigateBack({

    //   delta: 1,

    // })
  }
})